﻿<div class="modal-header blue-strip">
    <button type="button" class="close" aria-hidden="true" ng-click="cancel()">
        <!--&times;--></button>
    <h1 ng-i18next="SettingsTitle"></h1>
</div>

<div class="modal-body share-question-dialog">


    <ul class="nav nav-tabs" role="tablist">
        <li role="presentation" class="active">
            <a role="tab" data-toggle="tab" href="#questionnaireSettingsTab">{{'QuestionnaireSettings' | i18next }}</a>
        </li>
        <li role="presentation">
            <a role="tab" data-toggle="tab" href="#shareTab" ng-if="!questionnaire.isReadOnlyForUser || questionnaire.hasViewerAdminRights">{{'AccessSettings' | i18next }}</a>
        </li>
    </ul>

    <!-- Tab panes -->
    <div class="tab-content">
        <div role="tabpanel" class="tab-pane active" id="questionnaireSettingsTab">
            <div class="row well-sm">
                <div class="col-xs-7">
                    <form role="form" name="questionnaireForm">
                        <div class="form-group">
                            <label class="control-label" for="questionnaireTitle" ng-i18next="SettingsQuestionnaireName"></label>
                            <input id="questionnaireTitle"
                                   type="text" 
                                   class="form-control questionaire-title"
                                   ng-disabled="questionnaire.isReadOnlyForUser"
                                   ng-model="questionnaire.editedTitle"
                                   maxlength="2000">
                        </div>
                    
                        <div class="form-group input-variable-name"> 
                            <label class="control-label" for="questionnaireTitle">{{'SettingsQuestionnaireVariable' | i18next }}
                                <help key="questionnaireVariableName" />
                            </label>
                            <input id="questionnaireVariable" 
                                   ng-disabled="questionnaire.isReadOnlyForUser"
                                   type="text" class="form-control questionaire-title" ng-model="questionnaire.editedVariable"
                                maxlength="32" spellcheck="false">
                        </div>
                    
                        <!--i know this is horrible, but i cannot remove paddings from checkbox image so that visually they inputs are aligned-->
                        <div class="form-group" style="margin-left: -8px;">
                            <input id="questionnaireHideIdDisabled" type="checkbox" class="wb-checkbox" 
                                   ng-disabled="questionnaire.isReadOnlyForUser"
                                   ng-model="questionnaire.editedHideIfDisabled"/>
                            <label for="questionnaireHideIdDisabled"><span></span>{{'SettingsHideIfDisabled' | i18next}}</label>
                            <help key="hideIfDisabled" />
                        </div>
                        <div class="form-group">
                            <button type="submit" class="btn btn-lg update-button" ng-class="{ 'btn-primary': questionnaireForm.$dirty }"
                                unsaved-warning-clear ng-if="!questionnaire.isReadOnlyForUser" ng-disabled="!questionnaireForm.$dirty" ng-click="updateTitle()" ng-i18next>
                                Update
                            </button>
                        </div>
                    </form>
                </div>
                <div class="col-xs-5">
                    <img alt="qr code"
                         ng-src='{{"/questionnaire/publicurl/" + questionnaire.questionnaireId}}' />
                </div>
            </div>
        </div>
        <div role="tabpanel" class="tab-pane" id="shareTab">
            <div class="well-sm">
                <h2 ng-i18next="CollaboratorsSettings"> </h2>
                <em class="text-muted">{{ 'CollaboratorsDescriptionSettings' | i18next}}</em>
                <br/>
                <ul class="accounts">
                    <li ng-repeat="s in questionnaire.sharedPersons">
                        <a href="mailto:{{s.email}}">{{s.email}}</a> ({{s.login}}) -
                        <div class="btn-group">
                            <button type="button" class="btn btn-link dropdown-toggle" data-toggle="dropdown" ng-if="!s.isOwner">
                                {{ 'SettingsCan' | i18next }} {{ getShareType(s.shareType).text}}<span class="caret"></span>
                            </button>
                            <a href="javascript:void(0);" ng-if="s.isOwner" class="owner"><i ng-i18next="SettingsOwner"></i></a>
                            <ul class="dropdown-menu" role="menu">
                                <li>
                                    <a ng-click="revokeAccess(s)" href="javascript:void(0)" ng-i18next="SettingsRevokeAccess"></a>
                                </li>
                                <li ng-if="isQuestionnaireOwner()">
                                    <a ng-click="passOwnership(s)" href="javascript:void(0)" ng-i18next="SettingsMakeOwner"></a>
                                </li>
                            </ul>
                        </div>
                        <div ng-if="passConfirmationOpen === s.email" class="well">
                            <h2 ng-i18next="AreYouSure"></h2>
                            <p ng-i18next="MakeOwnerConfirmationMessage"></p>
                            <div class="btn-group">
                                <button type="button" class="btn btn-default" ng-click='passOwnershipConfirmation(s)' ng-i18next="Yes"></button>
                                <button type="button" class="btn btn-default" ng-click='passOwnershipCancel()' ng-i18next="Cancel"></button>
                            </div>
                        </div>
                    </li>
                </ul>
                <form role="form" class="row" name="viewModel.shareForm" novalidate>
                    <div class="col-xs-7">
                        <div class=" form-group" ng-class="{'has-error': viewModel.doesUserExist == false  }">
                            <label class="control-label" for="questionnaireTitle" ng-i18next="SettingsInviteCollaborators"></label>
                            <div class="input-group">
                                <input type="text" class="form-control" name="shareWithInput" ng-model="viewModel.shareWith" />
                                <div class="input-group-btn dropup share-type">
                                    <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"
                                        name="shareType" id="Share-type">
                                        {{viewModel.shareType.text}}
                                        <span class="caret"></span>
                                    </button>
                                    <ul class="dropdown-menu " role="menu" aria-labelledby="dropdownMenu1">
                                        <li role="presentation" ng-repeat="shareType in shareTypeOptions">
                                            <a role="menuitem" tabindex="-1" href="javascript:void(0);" ng-click="changeShareType(shareType)">
                                                {{shareType.text}}
                                            </a>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                            <p class="help-block ng-cloak" ng-show="viewModel.doesUserExist == false" ng-i18next="SettingsProvideExistingEmail"></p>
                        </div>
                    </div>
                    <div class="col-xs-5">
                        <div class="form-group pull-right">
                            <button class="btn btn-primary btn-lg invite-button" ng-click="invite()" ng-disabled="!viewModel.shareWith"
                                ng-i18next>SettingsInvite</button>
                        </div>
                    </div>
                </form>
                
                <hr />
                <div ng-if="isQuestionnaireOwner() || questionnaire.hasViewerAdminRights">
                    <h2 ng-i18next="AnonymousQuestionnaireSettings"></h2>
                    <em class="text-muted">{{ 'AnonymousQuestionnaireDescriptionSettings' | i18next}}</em>
                    <br/>
                    <span>
                        {{ (questionnaire.isAnonymouslyShared ? 'SettingsStatusAllowAnonymousAccess' : 'SettingsStatusDontAllowAnonymousAccess') | i18next }}
                    </span>
                    <button ng-if="isQuestionnaireOwner()" class="btn btn-link answer" ng-click="updateAnonymousQuestionnaireSettings()">
                        {{(questionnaire.isAnonymouslyShared ? 'SettingsTurnOffAnonymousAccess' : 'SettingsTurnOnAnonymousAccess') | i18next}}
                    </button>
                    <br />
                    <div ng-if="questionnaire.isAnonymouslyShared" class="row">
                        <div class="col-xs-7">

                            <div ng-i18next="AnonymousLink" style="margin-top: 15px"></div>
                            <a ng-href="{{ getAnonymousQuestionnaireLink() }}" style="word-break: break-word;" title="link" onclick="return false;">
                                {{ getAnonymousQuestionnaireLink() }}
                            </a>
                            <br/>
                            <div ng-i18next="({datetime: questionnaire.anonymousQuestionnaireShareDate})AnonymousQuestionnaireGeneratedDate">
                            </div>
                            <button class="btn btn-link answer" style="padding-left: 0px;" ng-i18next="CopyLink" ng-click="copyAnonymousQuestionnaireLink()">
                            </button>
                            
                            <span ng-if="isQuestionnaireOwner()"> | </span>

                            <button ng-if="isQuestionnaireOwner()" class="btn btn-link answer"  ng-click="regenerateAnonymousQuestionnaireLink()">
                                {{'RegenerateQuestionnaireSharingLink' | i18next }}
                            </button>
                        </div>
                        <div class="col-xs-5">
                            <img alt="qr code" ng-if="questionnaire.isAnonymouslyShared"
                                 ng-src='{{"/questionnaire/publicurl/" + questionnaire.anonymousQuestionnaireId}}' />
                        </div>
                    </div>
                </div>

                <hr ng-if="questionnaire.hasViewerAdminRights" />
                <div ng-if="questionnaire.hasViewerAdminRights">
                    <h2 ng-i18next="PublicAccessSettings"></h2>
                    <em class="text-muted">{{ 'PublicAccessDescriptionSettings' | i18next}}</em>
                    <br/>
                    <span>
                        {{ (questionnaire.isPublic ? 'PublicAccessSettingsStatusOn' : 'PublicAccessSettingsStatusOff') | i18next }}
                    </span>
                    <button class="btn btn-link answer" ng-click="togglePublicity()">
                        {{(questionnaire.isPublic ? 'PublicAccessSettingsOff' : 'PublicAccessSettingsOn') | i18next}}
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>
